//
//  Home_SystemAnnouncementView.m
//  Bullet
//
//  Created by admin on 2019/8/23.
//  Copyright © 2019 . All rights reserved.
//

#import "Home_SystemAnnouncementView.h"

@interface Home_SystemAnnouncementView()

@property (nonatomic,strong) NSTextCheckingResult *URLmatch;
@property (nonatomic,strong)UIButton * home_system_close;
@property (nonatomic,strong)UIButton * home_system_sende;
@end

@implementation Home_SystemAnnouncementView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = ColorHex_Alpha(@"000000", 0.62);
        self.home_system_Bgview_close = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, KScreen_W, KScreen_H)];
        self.home_system_Bgview_close.backgroundColor = [UIColor whiteColor];
        self.home_system_Bgview_close.alpha = 0.01;
        [self addSubview:self.home_system_Bgview_close];
        
        _home_system_tip = [[UILabel alloc]init];
        _home_system_tip.textColor = [UIColor whiteColor];
        _home_system_tip.textAlignment = NSTextAlignmentCenter;
        _home_system_tip.font = Font(13);
        [self.home_system_showBgImage addSubview:_home_system_tip];
        
//        self.home_system_close_bg = [[UIButton alloc]initWithFrame:CGRectMake(Ratio(215), Ratio(1), Ratio(30), Ratio(30))];
//        [self.home_system_showBgImage addSubview:self.home_system_close_bg];
    
        self.home_system_close = [[UIButton alloc]initWithFrame:CGRectMake(25, 125, 100, 44)];
        [self.home_system_close setTitle:@"取消" forState:UIControlStateNormal];
        [self.home_system_close setTitleColor:viewback_wite forState:UIControlStateNormal];
        self.home_system_close.layer.cornerRadius = 5;
        self.home_system_close.layer.borderColor = viewback_wite.CGColor;
        self.home_system_close.layer.borderWidth = 1;
        self.home_system_close.titleLabel.font = Font(14);
        [self.home_system_showBgImage addSubview:self.home_system_close];

        self.home_system_sende = [[UIButton alloc]initWithFrame:CGRectMake(155, 125, 100, 44)];
        [self.home_system_sende setBackgroundImage:[Tools changeImagSize:KImageNamed(@"mall_shop_buyBtn1") toSize:CGSizeMake(100, 44)] forState:UIControlStateNormal];
        [self.home_system_sende setTitle:@"提现" forState:UIControlStateNormal];
        [self.home_system_sende setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
        self.home_system_sende.layer.cornerRadius = 5;
        self.home_system_sende.clipsToBounds = YES;
        self.home_system_sende.titleLabel.font = FontBold(14);
        [self.home_system_showBgImage addSubview:self.home_system_sende];
        
        [self.home_system_sende addTarget:self action:@selector(systemViewSendTap) forControlEvents:UIControlEventTouchUpInside];
        [self.home_system_close addTarget:self action:@selector(systemViewCloseTap) forControlEvents:UIControlEventTouchUpInside];
        [self.home_system_Bgview_close addTarget:self action:@selector(systemViewCloseTap) forControlEvents:UIControlEventTouchUpInside];
    }
    return self;
}

- (UIImageView *)home_system_showBgImage{
    if (_home_system_showBgImage == nil) {
        _home_system_showBgImage = [[UIImageView alloc]initWithFrame:CGRectMake(65, KScreen_H/2-40, KScreen_W-130, 240)];
        _home_system_showBgImage.image = [UIImage imageNamed:@"ic_home_system_showBgImage"];
        _home_system_showBgImage.contentMode = UIViewContentModeScaleToFill;
        _home_system_showBgImage.userInteractionEnabled = YES;
        [self addSubview:_home_system_showBgImage];
        
        self.home_system_showBgImage1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 245, 60)];
        self.home_system_showBgImage1.image = [UIImage imageNamed:@"ic_home_system_showBgImage1"];
        self.home_system_showBgImage1.contentMode = UIViewContentModeScaleToFill;
        self.home_system_showBgImage1.userInteractionEnabled = YES;
        [_home_system_showBgImage addSubview:self.home_system_showBgImage1];
        
        self.home_system_showBgImage2 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 95, 245, 45)];
        self.home_system_showBgImage2.image = [UIImage imageNamed:@"ic_home_system_showBgImage2"];
        self.home_system_showBgImage2.contentMode = UIViewContentModeScaleToFill;
        self.home_system_showBgImage2.userInteractionEnabled = YES;
        [_home_system_showBgImage addSubview:self.home_system_showBgImage2];
    }
    return _home_system_showBgImage;
}

- (UILabel *)home_system_title{
    if (_home_system_title == nil) {
        _home_system_title = [[UILabel alloc]init];
        _home_system_title.textColor = [UIColor whiteColor];
        _home_system_title.textAlignment = NSTextAlignmentCenter;
        _home_system_title.font = FontMedium(14);
        [self.home_system_showBgImage addSubview:_home_system_title];
        
    }
    return _home_system_title;
}

- (UIButton *)home_system_centent{
    if (_home_system_centent == nil) {
        _home_system_centent = [[UIButton alloc]initWithFrame:CGRectMake(25, 50, 195, 40)];
        _home_system_centent.titleLabel.font = Font(22);
        _home_system_centent.titleLabel.numberOfLines = 0;
        _home_system_centent.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        [self.home_system_showBgImage addSubview:_home_system_centent];
    }
    return _home_system_centent;
}

- (UILabel *)home_system_time{
    if (_home_system_time == nil) {
        _home_system_time = [[UILabel alloc]initWithFrame:CGRectMake(25, 110, 200, 20)];
        _home_system_time.textColor = [UIColor whiteColor];
        _home_system_time.font = FontBold(18);
        _home_system_time.textAlignment = NSTextAlignmentRight;
        [self.home_system_showBgImage addSubview:_home_system_time];
    }
    return _home_system_time;
}

- (void)setHome_system_cententString:(NSString *)home_system_cententString{
    _home_system_cententString = home_system_cententString;
    CGSize strSize = [home_system_cententString boundingRectWithSize:CGSizeMake(280, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:Font(22)} context:nil].size;
    
    self.home_system_showBgImage.frame = CGRectMake((KScreen_W-280)/2, (KScreen_H-174)/2, 280, 200);
    
    self.home_system_tip.text = @"现在提现还可参与全额还活动";
    
    self.home_system_showBgImage1.frame = CGRectMake(0, 0, 280, 60);
    self.home_system_showBgImage2.frame = CGRectMake(0, 100+strSize.height-45, 280, 45);
    self.home_system_centent.frame = CGRectMake(25, 45, 230, 50);
    
    self.home_system_tip.frame = CGRectMake(25, 95, 230, 18);
    [self.home_system_centent setTitle:home_system_cententString forState:UIControlStateNormal];
}

- (void)setHome_system_titleString:(NSString *)home_system_titleString{
    _home_system_titleString = home_system_titleString;
    CGFloat titleHeight = [home_system_titleString boundingRectWithSize:CGSizeMake(MAXFLOAT, 20) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:FontMedium(14)} context:nil].size.width+3;
    self.home_system_title.frame = CGRectMake(280/2-titleHeight/2, 20, titleHeight, 20);
    self.home_system_title.text = home_system_titleString;
    UIView * leftLine = [[UIView alloc]initWithFrame:CGRectMake(280/2-titleHeight/2-20, 29.5, 15, 2)];
    leftLine.backgroundColor = [UIColor whiteColor];
    [self.home_system_showBgImage addSubview:leftLine];
    
    UIView * rightLine = [[UIView alloc]initWithFrame:CGRectMake(280/2+titleHeight/2+5, 29.5, 15, 2)];
    rightLine.backgroundColor = [UIColor whiteColor];
    [self.home_system_showBgImage addSubview:rightLine];
}

- (void)my_messege_detailedTap{
    [self systemViewCloseTap];
//    NSRange urlRange = [self.home_system_cententString fixLinkRangeWithMatch:self.URLmatch];
    NSString * URL = [self.home_system_cententString substringWithRange:self.URLmatch.range];
    [BConst openUrlWithStr:URL];
}

- (void)systemViewCloseTap{
    if(self.cDelegate && [self.cDelegate respondsToSelector:@selector(announceViewDidClickClose:)]){
        [self.cDelegate announceViewDidClickClose:0];
    }
    
}
- (void)systemViewSendTap{
    if(self.cDelegate && [self.cDelegate respondsToSelector:@selector(announceViewDidClickClose:)]){
        [self.cDelegate announceViewDidClickClose:1];
    }
}
@end
